package com.lc.controller;

import com.lc.entity.Order;
import com.lc.feign.UserDoOrderFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * Author:LC
 * Version:jdk-8u301
 * Date: 2022/7/19 11:00
 */
@RestController
public class UserController {

    @Autowired
    private UserDoOrderFeign userDoOrderFeign;

    /**
     * 使用feign：
     * 需要配置feign接口， 接口名自定。用@FeignClient注解，设置参数value=“目标服务名称”。
     * 将需要用到的方法标签复制到接口下，需要带请求接口。
     *
     * 浏览器(前端)-------> user-service(/userDoOrder)-----RPC(feign)--->order-service(/doOrder)
     * feign的默认等待时间时1s
     * 超过1s就直接报超时ReadTimeOut；因为feign的底层是ribbon，所以需要在配置文件中修改ribbon配置，或fegin配置
     * feign:
     *   client:
     *     config:
     *       default:
     *         connectTimeout: 10000
     *         readTimeout: 600000
     */
    @GetMapping("/userDoOrder")
    public String userDoOrder(){
        System.out.println("现在有一位用户进入");
        return userDoOrderFeign.doOrder();
    }


    @GetMapping("/testParam")
    public String testParam(){
        String s1 = userDoOrderFeign.getOneParam("lichuang");
        System.out.println(s1);

        String s2 = userDoOrderFeign.getTwoParam("xingyubo", 18);
        System.out.println(s2);

        Order order = Order.builder().id(1).name("order1").date(new Date()).build();
        String s3 = userDoOrderFeign.postOneParamOneObj(order, "wangzhiyi");
        System.out.println(s3);

        return "over";
    }

}
